package com.cybertron.ironhide.manage.action;

import java.util.List;

import javax.annotation.Resource;

import com.cybertron.ironhide.manage.common.base.BaseAction;
import com.cybertron.ironhide.manage.domain.Category;
import com.cybertron.ironhide.manage.domain.PopularCate;
import com.cybertron.ironhide.manage.service.CategoryService;
import com.cybertron.ironhide.manage.service.PopularCateService;

public class PopularCateAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3296553508685042428L;

	@Resource
	private PopularCateService popularCateService;

	@Resource
	private CategoryService categoryService;

	private List<PopularCate> popularCates;

	private List<Category> categories;

	private PopularCate popularCate;

	public String list() {
		popularCates = popularCateService.selectBySelective(popularCate, pager);
		return LIST;
	}

	public String add() {
		categories = categoryService.selectByLevel(1);
		return ADD;
	}

	public String doAdd() {
		PopularCate cate = popularCateService.selectByCateId(popularCate
				.getCateId());
		if (cate != null) {
			return ajaxError("该分类已添加");
		}
		popularCateService.insertSelective(popularCate);
		return ajaxSuccess("添加成功", "index-list", "index-list-box",
				CLOSE_CURRENT);
	}

	public String edit() {
		categories = categoryService.selectByLevel(0);
		popularCate = popularCateService
				.selectByPrimaryKey(popularCate.getId());
		return EDIT;
	}

	public String doEdit() {
		popularCateService.updateByPrimaryKeySelective(popularCate);
		return EDIT;
	}

	public String delete() {
		popularCateService.deleteByPrimaryKey(popularCate.getId());
		return ajaxSuccess("删除成功", "index-list", "index-list-box");
	}

	public List<PopularCate> getPopularCates() {
		return popularCates;
	}

	public void setPopularCates(List<PopularCate> popularCates) {
		this.popularCates = popularCates;
	}

	public PopularCate getPopularCate() {
		return popularCate;
	}

	public void setPopularCate(PopularCate popularCate) {
		this.popularCate = popularCate;
	}

	public List<Category> getCategories() {
		return categories;
	}

	public void setCategories(List<Category> categories) {
		this.categories = categories;
	}

}
